"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var iview_1 = require("iview");
var bggood_store_utils_1 = require("bggood-store-utils");
iview_1.LoadingBar.config({
    color: '#5cb85c',
});
var LoadingPlugin = {
    install: function (Vue, options) {
        options = options || {};
        options.obStateType = options.obStateType || bggood_store_utils_1.ObservablePromiseModel;
        Vue.prototype.loading = function (data) {
            var isLoading = false;
            if (data) {
                if (data.isResolved) {
                    isLoading = false;
                }
                else if (data.isTimeout) {
                    isLoading = false;
                }
                else if (data.isServerError) {
                    isLoading = false;
                }
                else if (!data.isOnLine) {
                    isLoading = false;
                }
                else if (data.isRejected) {
                    isLoading = false;
                }
                else {
                    isLoading = true;
                }
            }
            else {
                isLoading = true;
            }
            return isLoading;
        };
        Vue.prototype.pageLoadingBar = function (state) {
            if (state && state instanceof options.obStateType) {
                if (state.isPending && !state.isResolved) {
                    iview_1.LoadingBar.start();
                }
                else if (state.isResolved) {
                    iview_1.LoadingBar.finish();
                }
                else {
                    iview_1.LoadingBar.error();
                }
            }
        };
    }
};
exports.default = LoadingPlugin;
